package com.xm.business.controller;

import com.xm.common.core.controller.BaseController;
import com.xm.common.core.domain.AjaxResult;
import com.xm.common.utils.poi.ExcelUtil;
import com.xm.business.vo.AbTestVo;
import com.xm.business.service.IAbTestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.xm.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 测试啊啊啊Controller
 *
 * @author Tellsea
 * @date 2023-12-06
 */
@Api(tags = "测试啊啊啊")
@RestController
@RequestMapping("/business/test")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AbTestController extends BaseController {

    private final IAbTestService abTestService;

    @ApiOperation("查询测试啊啊啊列表")
    @PreAuthorize("@ss.hasPermi('business:test:list')")
    @GetMapping("/list")
    public TableDataInfo<AbTestVo> list(AbTestVo entity) {
        return abTestService.queryList(entity);
    }

    @ApiOperation("查询测试啊啊啊所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(AbTestVo entity) {
        return AjaxResult.success("查询成功", abTestService.queryAll(entity));
    }

    @ApiOperation("导出测试啊啊啊列表")
    @PreAuthorize("@ss.hasPermi('business:test:export')")
    //@Log(title = "测试啊啊啊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbTestVo entity) {
        List<AbTestVo> list = abTestService.queryAll(entity);
        ExcelUtil<AbTestVo> util = new ExcelUtil<>(AbTestVo.class);
        util.exportExcel(response, list, "测试啊啊啊数据");
    }

    @ApiOperation("获取测试啊啊啊详细信息")
    @PreAuthorize("@ss.hasPermi('business:test:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", abTestService.getById(id));
    }

    @ApiOperation("新增测试啊啊啊")
    @PreAuthorize("@ss.hasPermi('business:test:add')")
    //@Log(title = "测试啊啊啊", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody AbTestVo entity) {
        return toAjax(abTestService.save(entity));
    }

    @ApiOperation("修改测试啊啊啊")
    @PreAuthorize("@ss.hasPermi('business:test:edit')")
    //@Log(title = "测试啊啊啊", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody AbTestVo entity) {
        return toAjax(abTestService.updateById(entity));
    }

    @ApiOperation("删除测试啊啊啊")
    @PreAuthorize("@ss.hasPermi('business:test:remove')")
    //@Log(title = "测试啊啊啊", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(abTestService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
